package elephant.config;

import java.io.Reader;

import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * 
 * @author icecooly
 *
 */
public class ConfigManager {
	//
	private ScriptEngineManager manager;  
	private ScriptEngine engine; 
    
	public ConfigManager(){
		manager = new ScriptEngineManager();
		engine = manager.getEngineByName("nashorn");  
	}
	
	public void excute(Reader reader,ConfigContext ctx) throws ScriptException{
		ScriptContext sc=engine.getContext();
		sc.setAttribute("$", ctx, ScriptContext.ENGINE_SCOPE);
		sc.setAttribute("container", ctx, ScriptContext.ENGINE_SCOPE);
		engine.eval(reader, sc);
	}
}
